﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using dhDataAcess.produceLinq.StockLinq;

namespace dhDataAcess.produceDAL.Stock
{
  public   class productOrderStockListDAL
    {
                  string  tableName = "productOrderStockList";
        private SqlTransaction tran = null;
        private SqlConnection conn = null;
        public productOrderStockListDAL(SqlTransaction _transaction, SqlConnection _conn)
        {
            tran = _transaction ;
            conn = _conn;
        }
        /// <summary>
        /// 插入成品库存表数据
        /// </summary>
        /// <param name="deptRow"></param>
        /// <returns></returns>
        public int productOrderStockListInsert(productOrderStockListModel row)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
           // string insertstr = "insert into pbomMaster (mark,updateUser,updateDate,createUser,createDate,checkDate,spr,zbr,awgight,bweight,machineType,custNum,pname) values(@mark,@updateUser,@updateDate,@createUser,@createDate,@checkDate,@spr,@zbr,@awgight,@bweight,@machineType,@custNum,@pname)";
            string insertstr = baseBLL.dTableColumnRead.insertSqlStr(tableName).ToString();

            SqlParameter[] para = {
                                    new SqlParameter ("@createDate",row .createDate ),
                                    new SqlParameter ("@createUser",row .createUser ),
                                    new SqlParameter ("@stockDateAccount",row .stockDateAccount ),
                                    new SqlParameter ("@stockQtyTakeoutL",row .stockQtyTakeoutL ),
                                    new SqlParameter ("@stockQtyTakeinL",row .stockQtyTakeinL ),
                                    new SqlParameter ("@stockQtyTinL",row .stockQtyTinL ),
                                    new SqlParameter ("@stockOutL",row .stockOutL ),
                                    new SqlParameter ("@stockQtyToutL",row .stockQtyToutL),
                                    new SqlParameter ("@stockInL",row.stockInL),
                                    new SqlParameter ("@stockQtyQcL",row .stockQtyQcL),
                                    new SqlParameter ("@stockQtyKG",row .stockQtyKG),
                                    new SqlParameter ("@orderDetailNo",row .orderDetailNo ),
                                    new SqlParameter ("@pname",row .pname ),
                                    new SqlParameter ("@stockName",row .stockName )
                                };
            cmd.Parameters.AddRange(para);
            cmd.CommandText = insertstr;
            cmd.Transaction = tran;
            int i = cmd.ExecuteNonQuery();
            return i;
        }
        /// <summary>
        /// 更新成品库存表数据
        /// </summary>
        /// <param name="deptRow"></param>
        /// <returns></returns>
        public int productOrderStockListUpdate(productOrderStockListModel row)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            string updatestr = baseBLL.dTableColumnRead.updateSqlStr(tableName).ToString();

            SqlParameter[] para = {
                                    new SqlParameter ("@createDate",row .createDate ),
                                    new SqlParameter ("@createUser",row .createUser ),
                                    new SqlParameter ("@stockDateAccount",row .stockDateAccount ),
                                    new SqlParameter ("@stockQtyTakeoutL",row .stockQtyTakeoutL ),
                                    new SqlParameter ("@stockQtyTakeinL",row .stockQtyTakeinL ),
                                    new SqlParameter ("@stockQtyTinL",row .stockQtyTinL ),
                                    new SqlParameter ("@stockOutL",row .stockOutL ),
                                    new SqlParameter ("@stockQtyToutL",row .stockQtyToutL),
                                    new SqlParameter ("@stockInL",row.stockInL),
                                    new SqlParameter ("@stockQtyQcL",row .stockQtyQcL),
                                    new SqlParameter ("@stockQtyKG",row .stockQtyKG),
                                    new SqlParameter ("@orderDetailNo",row .orderDetailNo ),
                                    new SqlParameter ("@pname",row .pname ),
                                    new SqlParameter ("@stockName",row .stockName )
                                };
            cmd.Parameters.AddRange(para);
            cmd.CommandText = updatestr;
            cmd.Transaction = tran;
            int i = cmd.ExecuteNonQuery();
            return i;
        }
        /// <summary>
        /// 删除一行成品库存表数据
        /// </summary>
        /// <param name="deptRow"></param>
        /// <returns></returns>
        public int productOrderStockListDel(string recordID)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            string deletestr = baseBLL.dTableColumnRead.delSqlStr(tableName).ToString();
            SqlParameter[] para = {
                                     
                                        new SqlParameter ("@recordID",recordID )
                                   };
            cmd.Parameters.AddRange(para);
            cmd.CommandText = deletestr;
            cmd.Transaction = tran;
            int i = cmd.ExecuteNonQuery();
            return i;
        }
    }
}
